$(function () {
    product();
    $("#findPro").click(function () {
        empty();
        product($("#productTitleOne").val());
    })
    //回车事件
    $("body").keydown(function() {
        if (event.keyCode == "13") {//keyCode=13是回车键
            empty();
            product($("#productTitleOne").val());
        }
    });
})

function empty() {
    $("#product").empty();
    $("#hotline").empty();
    $("#logo").empty();
}
function product(productTitleOne) {
    // 请求后台
    $.ajax({
        url : "/init/product/webs/findProductLists",
        data : CommonUtils.encapsulationData({productTitleOne:productTitleOne}),
        type : 'post',
        dataType : 'json',
        async:false,
        contentType : "application/json",
        success : function(data) {
            if (data) {
                //获取图片路径
                var serverPath = CommonUtils.getServerRoot();
                // 产品
                var product = data.product;
                // 公司联系信息
                var contant = data.contant;
                var hotline = '<a title="免费咨询热线"><span>'+contant.contactPhone+'</span></a><u></u>';
                $("#hotline").append(hotline);
                // Logo图标
                var logo = '<img src="'+serverPath + contant.logoImg+'" alt="我的网站" class="img-responsive" />';
                $("#logo").append(logo);

                var re = new RegExp("\\\\","g");
                var html = "";
                for (var i=0;i<product.length;i++){
                    var products = product[i];
                    var imgURL = products.productImgUrl;
                    var imgPath = serverPath+imgURL;
                    //把图片路径中\该为/
                    imgPath = imgPath.replace(re, "/");

                    html += '<li class="cose_info  col-xs-10 col-sm-4 col-md-3 wow fadeInUp">\n' +
                        '                    <a href="product_detail.html?productId='+CommonUtils.compile(products.productId)+'" class="cose_conent">\n' +
                        '                        <img  src="'+imgPath+'" width="100%">\n' +
                        '                        <h3>'+products.productTitleOne+'</h3>\n' +
                        '                        <h5>'+products.productTitleTwo+'</h5>\n' +
                        '                    </a>\n' +
                        '                </li>';
                }
                $("#product").append(html);
            }
        }
    });
}